-- EscapeAction
-- create by chendh
-- 逃脱动作

EscapeAction = class("EscapeAction", function()
    return ActionBase.create();
end);

function EscapeAction.create(source)
    local self = EscapeAction.new();
    self.source = source;
    return self;
end

-- 构造函数
function EscapeAction:ctor()
end

-- 开始播放
function EscapeAction:play()
    self.state = ActionState.PLAYING;

    if self.source.type ~= OBJECT_TYPE_MONSTER then
        return 0;
    end

    delay = self:monsterEscape(self.source);

    self.state = ActionState.END;
    return 0;
end

-- 怪物逃脱
function EscapeAction:monsterEscape(source)
    local grids = UIDungeonMgr:getCurLevel():getAllGrids();
    local pos = source:getOwner();

    local duration = 0.1;
    local function callback()
        EventMgr.fire(event.MONSTER_FLEE, { ["pos"] = pos, });
    end
    performWithDelay(UIDungeonMgr:getCurLevel(), callback, duration);

    return duration;
end

return EscapeAction;